﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_ShowTravelPlanControl : System.Web.UI.UserControl
{
    private string check = null;
    private string getdate = null;
    private string getslocation = null;
    private string getelocation = null;
    ListAndProcessData wsv = new ListAndProcessData();
    protected void Page_Load(object sender, EventArgs e)
    {
       
        CalendarExtender1.SelectedDate = DateTime.Now;
        check = Request.QueryString["Loi"];
        //check = Convert.ToInt32(loi);
        getdate = Request.QueryString["date"];
        getslocation = Request.QueryString["slocation"];
        getelocation = Request.QueryString["elocation"];
        var a = wsv.getTravelPlan();
        foreach (var item in a)
        {
            dropdownlist1.Items.Add(item.StartLocation);
            dropdownlist2.Items.Add(item.EndLocation);
            
        }
        try
        {
            if (check == "404")
            {
                lblnull.Visible = true;
                ListView1.DataSource = wsv.getTravelPlan();
                ListView1.DataBind();
            }
            else
            {
                string date = getdate;
                string slocation = getslocation;
                string elocation = getelocation;
                var content = wsv.searchtravelplan(slocation, elocation, date);
                if (content.Count != 0)
                {
                    ListView1.Items.Clear();
                    ListView1.DataSource = content;
                    ListView1.DataBind();
                }
                else
                {
                    Response.Redirect("ShowTravelPlan_Admin.aspx?Loi=404");
                }


            }
        }
        catch (Exception)
        {
            ListView1.DataSource = wsv.getTravelPlan();
            ListView1.DataBind();

        }
        
    }
    protected void btnsearch_Click(object sender, EventArgs e)
    {
        
        if (check == "404")
        {
            Response.Redirect("ShowTravelPlan_Admin.aspx?slocation=" + dropdownlist1.SelectedItem.ToString() + "&&elocation=" + dropdownlist2.SelectedItem.ToString() + "&&date=" +txtstartdate.Text);
        }
        else
        {
            Response.Redirect("ShowTravelPlan_Admin.aspx?slocation=" + dropdownlist1.SelectedItem.ToString() + "&&elocation=" + dropdownlist2.SelectedItem.ToString() + "&&date=" + txtstartdate.Text);
        }
    }
}